package com.fucheng.common;

import lombok.Builder;
import lombok.Data;

import java.io.Serializable;

/**
 * 客户端接收RpcResponse，取出结果返回给调用者
 */
@Data
@Builder
public class RpcResponse implements Serializable {
    // 状态信息
    private int code;
    private Object data;      // 返回值
    private String message;   // 可选：返回信息或错误信息

    public RpcResponse() {}

    public RpcResponse(int code, Object data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    private static RpcResponse success(Object data) {
        RpcResponse rpcResponse = RpcResponse.builder()
                .code(200)
                .data(data)
                .build();
        return rpcResponse;
    }

    private static RpcResponse fail() {
        RpcResponse rpcResponse = RpcResponse.builder()
                .code(500)
                .message("服务器发生错误")
                .build();
        return rpcResponse;
    }
}
